<?php

namespace App\Kuafu\Activity\Model;

use App\Kuafu\Base\Model\BaseModel;
use App\Kuafu\Base\Model\Traits\KfSoftDeletes;

class ActivityImageMappingModel extends BaseModel
{
    protected $connection = 'mysql';
    protected $table      = 'activity_image_mappings';
    protected $primaryKey = 'id';

    protected $fillable = [
        'activityId',
        'imageUrl',
        'createdAt',
        'updatedAt',
        'type',
    ];

    const TYPE_TEXT = [
        self::TYPE_DEFAULT                 => '默认活动图',
        self::TYPE_MINI_IMAGE_UPLOAD       => '小程序卡片上传图',
        self::TYPE_MINI_IMAGE_INNER        => '公众号的小程序二维码素材',
        self::TYPE_OFFICIAL_IMAGE_GENERATE => '公众号的二维码图片',
        self::TYPE_OFFICIAL_IMAGE_INNER    => '公众号的公众号二维码素材',
        self::TYPE_MATERIAL_COMPRESS       => '私域活动物料素材压缩包',
    ];

    const TYPE_DEFAULT                 = 0;
    const TYPE_MINI_IMAGE_UPLOAD       = 1;
    const TYPE_MINI_IMAGE_INNER        = 2;
    const TYPE_OFFICIAL_IMAGE_GENERATE = 3;
    const TYPE_OFFICIAL_IMAGE_INNER    = 4;
    const TYPE_MATERIAL_COMPRESS       = 5;


    public static function getImageListByIdAll($activityId)
    {
        return self::query()
                   ->where('activityId', $activityId)
                   ->orderBy('id')
                   ->get();
    }

    public static function getImageListById($activityId)
    {
        return self::query()
                   ->where('activityId', $activityId)
                   ->where('type', self::TYPE_DEFAULT)
                   ->orderBy('id')
                   ->get();
    }

    public static function getImageListByIdNoDefault($activityId)
    {
        return self::query()
                   ->where('activityId', $activityId)
                   ->where('type', '!=', self::TYPE_DEFAULT)
                   ->orderBy('id')
                   ->get();
    }

}
